package intranet.client;

import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.regexp.shared.RegExp;
import com.google.gwt.user.client.ui.TextBox;

public class ValidIntegerTextBox extends TextBox
{
	private final static String VALIDATION_REGEX = "[^0-9.]";
	
	public ValidIntegerTextBox()
	{
		super();
		this.addKeyUpHandler(new KeyUpHandler()
		{
			public void onKeyUp(KeyUpEvent event)
			{
				String s = ((TextBox)event.getSource()).getText();
				RegExp reg = RegExp.compile(VALIDATION_REGEX);
				
				while (reg.test(s))
					if(reg.test(s))
					{
						((TextBox)event.getSource()).setText(reg.replace(s, ""));
						s=((TextBox)event.getSource()).getText();
					}
			}
		});
	}
	
	

	
	

}
